cmake_minimum_required(VERSION 3.5)

project(precision VERSION 0.1 LANGUAGES CXX)

set(CMAKE_AUTOUIC ON)
set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTORCC ON)

set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

find_package(Qt5 COMPONENTS Network Widgets Sql SerialBus Charts REQUIRED)

include_directories(
    ${CMAKE_CURRENT_SOURCE_DIR}
)

file(GLOB ALL_CPP_FILES
    ${CMAKE_CURRENT_SOURCE_DIR}/*.cpp

)
file(GLOB ALL_CPP_H_FILES
    ${CMAKE_CURRENT_SOURCE_DIR}/*.h
)
file(GLOB ALL_UI_FILES
    ${CMAKE_CURRENT_SOURCE_DIR}/*.ui
    )
file(GLOB QRC_SOURCE_FILES
    ${CMAKE_CURRENT_SOURCE_DIR}/*.qrc
    ${CMAKE_CURRENT_SOURCE_DIR}/translation/*.qrc)

file(GLOB QM_SOURCE_FILES 
    ${CMAKE_CURRENT_SOURCE_DIR}/translation/*.qm)

######################################################
set(TS_DIR ${CMAKE_SOURCE_DIR}/translation)

set(TS_FILES
    ${TS_DIR}/precision_zh_CN.ts
)

find_program(LUPDATE_EXECUTABLE lupdate)
find_program(LRELEASE_EXECUTABLE lrelease)


foreach(_ts_file ${TS_FILES})
    execute_process(
        COMMAND ${LUPDATE_EXECUTABLE} -recursive ${CMAKE_SOURCE_DIR} -ts ${_ts_file})
    execute_process(
        COMMAND ${LRELEASE_EXECUTABLE} ${_ts_file})
endforeach()
#############################

add_executable(precision
        ${ALL_CPP_FILES}
        ${ALL_CPP_H_FILES}
        ${ALL_UI_FILES}
        ${QRC_SOURCE_FILES}
        ${QM_SOURCE_FILES}
)

target_link_libraries(precision PRIVATE
    Qt5::Widgets Qt5::Network Qt5::Sql Qt5::SerialBus Qt5::Charts)


set_target_properties(precision PROPERTIES
    ${BUNDLE_ID_OPTION}
    MACOSX_BUNDLE_BUNDLE_VERSION ${PROJECT_VERSION}
    MACOSX_BUNDLE_SHORT_VERSION_STRING ${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}
    MACOSX_BUNDLE TRUE
    WIN32_EXECUTABLE TRUE
)

include(GNUInstallDirs)
install(TARGETS precision
    BUNDLE DESTINATION .
    LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
    RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
)


if(QT_VERSION_MAJOR EQUAL 6)
    qt_finalize_executable(precision)
endif()
